package cn.offcn.controller;

import cn.offcn.entity.Btype;
import cn.offcn.service.BtypeService;
import cn.offcn.utils.OAResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/btype")
public class BtypeController {

    @Autowired
    private BtypeService btypeService;

    @RequestMapping("/{page}")
    public String forwardPage(@PathVariable("page") String page, Integer typeid, Model model){
        model.addAttribute("typeid",typeid);
        return "type/"+page;
    }

    @RequestMapping("/bigList")
    @ResponseBody
    public List<Btype> getBtypes(){

        return btypeService.getBtypes();
    }

    @RequestMapping("/addBtype")
    @ResponseBody
    public OAResult addBtype(Btype bytpe){

       return btypeService.addBtype(bytpe);
    }

    @RequestMapping("/getSmallList")
    @ResponseBody
    public List<Btype> getSmallList(int typeid){

        return btypeService.getSmallList(typeid);
    }

    @RequestMapping("/deleteSubType")
    @ResponseBody
    public OAResult deleteSubType(int typeid){
        return btypeService.deleteSubType(typeid);
    }

    @RequestMapping("/getBtypeById")
    @ResponseBody
    public Btype getBtypeById(int typeid){
        return btypeService.getBtypeById(typeid);
    }

    @RequestMapping("/updateBtypeById")
    @ResponseBody
    public OAResult updateBtypeById(Btype btype){

        return btypeService.updateBtypeById(btype);
    }

    @RequestMapping("/deleteBigBtype")
    @ResponseBody
    public OAResult deleteBigBtype(int typeid){
        return btypeService.deleteBigBtype(typeid);
    }
}
